@file:OptIn(ExperimentalNativeApi::class)

package com.example.kotlin_library

import kotlinx.cinterop.*
import com.example.kotlin_library.native.*
import kotlin.experimental.ExperimentalNativeApi


/**
 * OHOS 平台的 AnimatedImageDecoder 实现
 */
actual object AnimatedImageDecoderFactory {
    @CName("create_heif_image_kotlin")
    @OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
    actual fun decode(filePath: String, width: Float, height: Float): ImageDecodeResult {
        val handle = create_heif_image(filePath, width, height)
        return ImageDecodeResult(
            handle = handle,
            isValid = handle != 0L
        )
    }

    @OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
    @CName("destroy_heif_image_kotlin")
    actual fun release(handle: Long) {
        if (handle != 0L) {
            destroy_heif_image(handle)
        }
    }
}
